package com.jjh.jhwebserver.io;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Objects;

/**
 * @author JJH
 */
public class JhOutputStream extends OutputStream {

    private byte[] bytes;

    public JhOutputStream(byte[] bytes){
        this.bytes = bytes;
    }

    /**
     * 单个字写
     * @param b
     * @throws IOException
     */
    @Override
    public void write(int b) throws IOException {
        /**
         * 这里的write和我们平时用的write不一样，它实际上
         * 是吧内容存放到一个字节数组中，相当于缓冲区
         */
        int i = 0;
        while (bytes[i]!=0){
            i++;
        }
        bytes[i] = (byte) b;
    }

    /**
     * 每次写一个数组
     * @param bytes   the data.
     */
    @Override
    public void write(byte[] bytes){

        for(int i =0;i<bytes.length;i++){
            this.bytes[i] = bytes[i];
        }


    }




}
